<template>
  <div class="ver-layout-center">
    <el-card header="OpenAi使用情况">
      <el-descriptions title="使用情况">
        <el-descriptions-item v-if="errorObj" label="错误信息" :labelStyle="{color:'red'}" :contentStyle="{color:'red'}">
          {{ errorObj.message }}
        </el-descriptions-item>
        <el-descriptions-item label="截至时间">{{ openAiObj.access_until1 }}</el-descriptions-item>
      </el-descriptions>
    </el-card>
  </div>
</template>

<script>
import {openAiApi} from "@/api/openai.js"
import {formatDateTime} from "../utils/util.js"

export default {
  name: "home",
  data() {
    return {
      openAiObj: {},
      errorObj: null
    }
  },
  created() {
  },
  mounted() {
    this.getOpenAiInfo()
  },
  methods: {
    getOpenAiInfo() {
      openAiApi.getApiUseInfo().then(res => {
        this.errorObj = res.code && res.msg
        if (res.code != 0) return
        this.openAiObj = res.data
        this.openAiObj.access_until1 = formatDateTime(new Date(res.data.access_until * 1000))
      })
    }
  }
}
</script>

<style scoped>

</style>
